<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;



//后台模块表
class UserWalletModel extends Model
{
    //定义一个表名
    protected $table = 'user_wallet';
    //定义主键
    protected $primaryKey = 'id';
	protected $guarded = [];
	static public function handleAccount($uid, $num, $sign, $msg, $type, $status, $dy_table='', $dy_id=0,$befor=0,$after=0)
	{
		$account_log = new UserWalletLogModel();
		switch ($type) {
			case 1:
				// 现金
				$befor = UserWalletModel::where("uid", $uid)->value("money");
				if ($sign == "+") {
					UserWalletModel::where("uid", $uid)->increment("money", $num);
				} elseif ($sign == "-") {
					UserWalletModel::where("uid", $uid)->decrement("money", $num);
				}
				$after = UserWalletModel::where("uid", $uid)->value("money");
				$msg .= ",现金余额" . $after;
				break;
			case 2:
				// 货款
				$befor = UserWalletModel::where("uid", $uid)->value("lock_money");
				if ($sign == "+") {
					UserWalletModel::where("uid", $uid)->increment("lock_money", $num);
				} elseif ($sign == "-") {
					UserWalletModel::where("uid", $uid)->decrement("lock_money", $num);
				}
				$after = UserWalletModel::where("uid", $uid)->value("lock_money");
				$msg .= ",货款余额" . $after;
				break;
		}
		$account_log->add_log($uid, $num, $sign, $msg, $befor, $after, $type, $status, $dy_table, $dy_id);
	}
 
}
